#pragma once

#include "Clickable.h"
#include "Definitions.h"

class Square;

class Grid : public Clickable
{
protected:
	Square * square[BOARD_SIZE][BOARD_SIZE];
protected:
	virtual void fillGrid()=0;
	XY SquareOver(XY);
	void PrepDraw();
protected:
	Square* getSquare(XY s)		{return square	[s.x]	[s.y];}
	Square* getNorth(XY n)		{if(n.y == 0)											return NULL; return square	[n.x]	[n.y-1];}
	Square* getSouth(XY s)		{if(s.y == LAST_ROW_COLUMN)								return NULL; return square	[s.x]	[s.y+1];}
	Square* getEast(XY e)		{if(e.x == LAST_ROW_COLUMN)								return NULL; return square	[e.x-1]	[e.y];}
	Square* getWest(XY w)		{if(w.x == 0)											return NULL; return square	[w.x+1]	[w.y];}
	Square* getNorthEast(XY ne)	{if(ne.y == 0 || ne.x == LAST_ROW_COLUMN)				return NULL; return square	[ne.x-1][ne.y-1];}
	Square* getNorthWest(XY nw)	{if(nw.y == 0 || nw.x == 0)								return NULL; return square	[nw.x+1][nw.y-1];}
	Square* getSouthEast(XY se)	{if(se.y == LAST_ROW_COLUMN || se.x == LAST_ROW_COLUMN)	return NULL; return square	[se.x-1][se.y+1];}
	Square* getSouthWest(XY sw)	{if(sw.y == LAST_ROW_COLUMN || sw.x == 0)				return NULL; return square	[sw.x+1][sw.y+1];}
public:
	Grid()	{type = GRID;}
	virtual void Update(MouseInfo)=0;
	void Draw();
};